package hu.diploma.web.server.serviceimpl;

import hu.diploma.common.service.GroupService;
import hu.diploma.common.vos.GroupVo;
import hu.diploma.core.util.ServiceProviderImpl;
import hu.diploma.web.client.service.WebGroupService;
import hu.diploma.web.server.util.TransformUtil;
import hu.diploma.web.shared.webvos.GroupWebVo;

import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class WebGroupServiceImpl extends RemoteServiceServlet implements WebGroupService {
	private final GroupService groupService = ServiceProviderImpl.getServiceProvider().getGroupService();

	public List<GroupWebVo> loadByDevice(Long deviceId) throws Exception {
		List<GroupVo> groups = groupService.findByDevice(deviceId);

		return TransformUtil.groupVoToGroupWebVo(groups);
	}

	public void addPersonToGroup(Long personId, Long groupId) throws Exception {

		groupService.addPersonToGroup(personId, groupId);
	}

	public void movePersonToGroup(Long personId, Long groupFromId, Long groupToId) throws Exception {

		groupService.movePersonToGroup(personId, groupFromId, groupToId);
	}

	public void addPersonToGroup(List<Long> personIds, Long groupId) throws Exception {
		for (Long id : personIds) {
			groupService.addPersonToGroup(id, groupId);
		}

	}

	public void movePersonToGroup(List<Long> personIds, Long groupFromId, Long groupToId) throws Exception {
		for (Long id : personIds) {
			groupService.movePersonToGroup(id, groupFromId, groupToId);
		}
	}

	public void removePersonFromGroup(Long personId, Long groupId) throws Exception {

		groupService.removePersonToGroup(personId, groupId);
	}

}
